﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Internet_Cafe.App_Code.DatabaseModel;
using Internet_Cafe.App_Code.DataBaseAccess;
using Internet_Cafe.App_Code;

namespace Internet_Cafe
{
    /// <summary>
    /// Interaction logic for Login.xaml
    /// </summary>
    public partial class Login : Window
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            User user = null;
            bool isAdmin = (cmbLogin.SelectedIndex == 0 ? true : false);
            if (isAdmin)
                user = DbUsersAccess.GetAdmin(txtUserName.Text, txtPassword.Password);
            else 
                user = DbUsersAccess.GetWorker(txtUserName.Text, txtPassword.Password);
             
            if (user != null)
            {
                AppHelper.LoggedUser = new UserViewModel(user, isAdmin);

                MainWindow mw = new MainWindow();
                mw.Show();
                this.Close();
            }
            else
            {
                ErrorMsg.Visibility = System.Windows.Visibility.Visible;
            }
        }
    }
}
